package com.java.jigsaw.test;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

public class MyJFrame2 extends JFrame implements MouseListener {

    //创建一个按钮对象
    JButton jtb1 = new JButton("点我啊");
    JButton jtb2 = new JButton("再点我啊");

    public MyJFrame2(){
        this.setSize(603, 680);
        this.setTitle("拼图单机版 v1.0");
        this.setAlwaysOnTop(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        this.setLayout(null);

        jtb1.setBounds(0,0,100,50);
        jtb1.addMouseListener(this);

        jtb2.setBounds(100,0,100,50);
        jtb2.addMouseListener(this);

        this.getContentPane().add(jtb1);
        this.getContentPane().add(jtb2);

        this.setVisible(true);
    }


    @Override
    public void mouseClicked(MouseEvent e) {
        Object o = e.getSource();
        if(o==jtb1){
            System.out.println("单击1");
        }else if(o==jtb2) {
            System.out.println("单机2");
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按下不松");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("划入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("划出");
    }
}
